package com.xhai.controller;

import com.xhai.admin.service.LoginService;
import com.xhai.common.domain.ResponseResult;
import com.xhai.common.domain.login.LoginForm;
import com.xhai.common.domain.login.LoginSucInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author xhai
 * @description 登录控制器
 * @date 2025/5/25
 */
@RestController
@RequestMapping
@Tag(name = "登录控制器", description = "登录控制器")
public class LoginController {

    @Resource
    private LoginService loginService;

    /**
     * 登录接口
     *
     * @param loginForm 登录表单
     * @return 登录成功信息
     */
    @PostMapping("/login")
    @Operation(summary = "登录", description = "登录")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "登录成功"),
            @ApiResponse(responseCode = "400", description = "登录失败")
    })
    @Parameters({
            @Parameter(name = "loginForm", description = "登录表单", schema = @Schema(implementation = LoginForm.class)),
    })
    public ResponseResult<?> login(@RequestBody LoginForm loginForm) {
        LoginSucInfo loginSucInfo = loginService.login(loginForm.getUsername(), loginForm.getPassword(), loginForm.getCaptchaCode(), loginForm.getCaptchaUuid());
        return ResponseResult.success(loginSucInfo);
    }
}
